package com.acic.jba.db;

import java.io.File;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;

import org.nutz.dao.Dao;
import org.nutz.lang.Files;

import com.assic.utils.db.DBImportor;
import com.assic.utils.db.SqlActuator;
import com.assic.utils.db.Sqls;

public class DataFetcher {

	public static List<LinkedHashMap<String, Object>> getData(String sql) {
		return SqlActuator.runReportSql(sql, DaoFactory.getDao(DaoFactory.ORACLE)).getData();
	}

	public static long insertData(File file, Dao dao) throws IOException {
		return DBImportor.importFromInsertFile(file, dao);
	}

	public static void main(String[] args) throws IOException {
		
		List<LinkedHashMap<String, Object>> list = getData("SELECT * FROM ODS_PLY_CVRG");
		
		for (LinkedHashMap<String, Object> map : list) {
			Files.appendWrite(new File("ODS_PLY_CVRG.SQL"), Sqls.genInsertSql(map, "ODS_PLY_CVRG"));
		}
		
//		Files.appendWrite(new File("C:/Users/Kerbores/Desktop/sql/ods_ply_cvrg.sql"), Files.read(new File("C:/Users/Kerbores/Desktop/sql/ply_cvrg.sql")).replaceAll("jba_ply_cvrg", "ods_ply_cvrg"));
//		Timer.start();
//		insertData(new File("C:/Users/Kerbores/Desktop/sql/ods_ply_cvrg.sql"), DaoFactory.getDao(DaoFactory.ORACLE));
//		Timer.end();
	}
}
